package com.zhongxi.guoyuan.adapter.rewardCoinOrder;

import android.Manifest;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.Html;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.baidu.navisdk.adapter.BNRoutePlanNode;
import com.baidu.navisdk.adapter.BaiduNaviManager;
import com.bumptech.glide.Glide;
import com.zhongxi.guoyuan.R;
import com.zhongxi.guoyuan.adapter.GridOrderAdapter;
import com.zhongxi.guoyuan.adapter.RewardOrderAdapter;
import com.zhongxi.guoyuan.application.MyApplication;
import com.zhongxi.guoyuan.entity.rewardcoin.MirrorInfo;
import com.zhongxi.guoyuan.entity.rewardcoin.RewardCoinOrderInfo;
import com.zhongxi.guoyuan.fragment.RewardCoinOrder.RewardOrderHasNoTokenFragment;
import com.zhongxi.guoyuan.url.Url;
import com.zhongxi.guoyuan.utils.CommonTool;
import com.zhongxi.guoyuan.utils.Constants;
import com.zhongxi.guoyuan.utils.DataUtil;
import com.zhongxi.guoyuan.view.MapNaviActivity;
import com.zhongxi.guoyuan.view.personalCenter.RewardCoinOrderActivity;
import com.zhongxi.guoyuan.widget.goldshop.NoScrollGridView;
import com.zhongxi.guoyuan.widget.sliding.NoScrollListView;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/11/21.
 */

public class RewardOrderHasNoTokenAdapter extends BaseAdapter {

    private RewardOrderHasNoTokenFragment fragment;
    private Context context;
    private List<RewardCoinOrderInfo> list;
    private LayoutInflater mLayoutInflater;

    private int mExpandedMenuPos = -1;
    private Handler handler;
    private JSONObject info;
    private JSONObject shopInfo;
    private JSONObject orderCus;
    private RewardCoinOrderInfo data;
    private String dimensions;
    private String longitude;
    private ProgressDialog dialog;
    private final static String authComArr[] = {Manifest.permission.READ_PHONE_STATE};
    private int authComRequestCode = 2;
    private boolean hasRequestComAuth = false;
    private DialogInterface.OnKeyListener keyListener = new DialogInterface.OnKeyListener() {
        @Override
        public boolean onKey(DialogInterface dialogInterface, int i, KeyEvent keyEvent) {
            if (i == KeyEvent.KEYCODE_BACK && keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
                if (dialog != null && dialog.isShowing()) {
                    dialog.dismiss();
                }
            }
            return false;
        }
    };

    private String status;

    public RewardOrderHasNoTokenAdapter(Context context, List<RewardCoinOrderInfo> data, Handler handler, RewardOrderHasNoTokenFragment fragment) {
        this.context = context;
        this.mLayoutInflater = LayoutInflater.from(context);
        this.list = data;
        this.handler = handler;
        this.fragment = fragment;
    }

    public int getmExpandedMenuPos() {
        return mExpandedMenuPos;
    }

    public void setmExpandedMenuPos(int mExpandedMenuPos) {
        this.mExpandedMenuPos = mExpandedMenuPos;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }


    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        try {
            ViewHolder holder = null;
            if (convertView == null) {
                holder = new ViewHolder();
                convertView = mLayoutInflater.inflate(R.layout.item_reward_order, parent, false);

                holder.ivSingleImg = convertView.findViewById(R.id.ivSingleImg);
                holder.gvImg = convertView.findViewById(R.id.gvImg);
                holder.listMenu = convertView.findViewById(R.id.listMenu);
                holder.ivImg = (ImageView) convertView.findViewById(R.id.ivImg);

                holder.gvList = (NoScrollGridView) convertView.findViewById(R.id.gvList);

                holder.rewardProjectType = (TextView) convertView.findViewById(R.id.reward_project_type);
                holder.rewardProjectMoney = (TextView) convertView.findViewById(R.id.reward_project_money);
                holder.rewardProjectHongdou = (TextView) convertView.findViewById(R.id.reward_project_hongdou);
                holder.rewardProjectMeidou = (TextView) convertView.findViewById(R.id.reward_project_meidou);
                holder.rewardProjectPaytime = (TextView) convertView.findViewById(R.id.reward_project_paytime);
                holder.rewardProjectToPay = (TextView) convertView.findViewById(R.id.reward_project_toPay);
                holder.rewardProjectDelete = (TextView) convertView.findViewById(R.id.reward_project_delete);

                holder.rewardProjectStatus = (TextView) convertView.findViewById(R.id.reward_project_status);
                holder.rewardProjectConfirm = (TextView) convertView.findViewById(R.id.reward_project_confirm);
                holder.rewardProjectToView = (TextView) convertView.findViewById(R.id.reward_project_toView);

                holder.rewardShopName = (TextView) convertView.findViewById(R.id.reward_shop_name);
                holder.linearShopPhone1 = (LinearLayout) convertView.findViewById(R.id.linear_shopPhone1);
                holder.linearShopPhone2 = (LinearLayout) convertView.findViewById(R.id.linear_shopPhone2);
                holder.rewardZiTiCall = (TextView) convertView.findViewById(R.id.reward_ziti_call);
                holder.rewardZiTiNavigate = (TextView) convertView.findViewById(R.id.reward_ziti_navigate);
                holder.rewardShopPhone = (TextView) convertView.findViewById(R.id.reward_shop_phone);
                holder.rewardShopPhone2 = (TextView) convertView.findViewById(R.id.reward_shop_phone2);
                holder.rewardShopAddress = (TextView) convertView.findViewById(R.id.reward_shop_address);

                holder.rewardProjectItemOrderNum = (TextView) convertView.findViewById(R.id.reward_projectItem_orderNum);

                holder.linearTop = (LinearLayout) convertView.findViewById(R.id.linear_top);
                holder.lvList = (NoScrollListView) convertView.findViewById(R.id.lvList);

                holder.rewardProjectItemAllCash = (TextView) convertView.findViewById(R.id.reward_projectItem_allCash);
                holder.rewardProjectItemHongdou = (TextView) convertView.findViewById(R.id.reward_projectItem_hongdou);
                holder.rewardProjectItemMeidou = (TextView) convertView.findViewById(R.id.reward_projectItem_meidou);
                holder.rewardProjectItemTvSend = (TextView) convertView.findViewById(R.id.reward_projectItem_tvSend);
                holder.rewardGetName = (TextView) convertView.findViewById(R.id.reward_get_name);
                holder.rewardGetPhone = (TextView) convertView.findViewById(R.id.reward_get_phone);
                holder.rewardGetAddress = (TextView) convertView.findViewById(R.id.reward_get_address);

                holder.rewardPostShopCall = (TextView) convertView.findViewById(R.id.reward_post_shopCall);
                holder.rewardPostShopName = (TextView) convertView.findViewById(R.id.reward_post_shopName);
                holder.rewardPostShopPhone = (TextView) convertView.findViewById(R.id.reward_post_shopPhone);

                holder.linearTopStatus = (RelativeLayout) convertView.findViewById(R.id.linear_topStatus);
                holder.linearBottom = (LinearLayout) convertView.findViewById(R.id.linear_bottom);
                holder.linearCenter = (LinearLayout) convertView.findViewById(R.id.linear_center);
                holder.rewardSendCash= (TextView) convertView.findViewById(R.id.reward_send_cash);
                holder.rewardProjectItemSend= (TextView) convertView.findViewById(R.id.reward_projectItem_sendCash);
                convertView.setTag(holder);
            } else {
                holder = (ViewHolder) convertView.getTag();
            }

            holder.rewardProjectToPay.setText("去评价");
            holder.rewardProjectDelete.setVisibility(View.GONE);

            if (null != list.get(position) && !"".equals(list.get(position))) {
                data = list.get(position);
                final JSONObject jsonObject = shopInfo.optJSONObject(data.getShopid());

                holder.listMenu.setVisibility(position == mExpandedMenuPos ? View.VISIBLE : View.GONE);
                //去评价
                holder.rewardProjectToPay.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (null != jsonObject && !"".equals(jsonObject)) {
                            status = jsonObject.optString("status");
                            if (status.equals("0")) {
                                // Toast.makeText(context, "该店铺已关闭", Toast.LENGTH_SHORT).show();
                            } else {
                                Message msg = Message.obtain();
                                msg.obj = position;
                                msg.what = 0;
                                handler.sendMessage(msg);
                            }
                        } else {
                            Toast.makeText(context, "店铺已关闭", Toast.LENGTH_SHORT).show();
                        }
                    }
                });
                if (!TextUtils.isEmpty(data.getBackredbean()) && !TextUtils.isEmpty(data.getBackinnernum())) {
                    if (DataUtil.moreThanZero(data.getBackredbean()) && DataUtil.moreThanZero(data.getBackinnernum())) {
                        holder.rewardProjectHongdou.setVisibility(View.VISIBLE);
                        holder.rewardProjectItemHongdou.setVisibility(View.VISIBLE);
                        holder.rewardProjectHongdou.setText(context.getResources().getString(R.string.award_hongdou) +  CommonTool.getWhole(DataUtil.multiplys(data.getShouldprice(), Constants.REDBEAN_RATE, 2))  + "红豆");
                        holder.rewardProjectItemHongdou.setText(context.getResources().getString(R.string.award_hongdou) +  CommonTool.getWhole(DataUtil.multiplys(data.getShouldprice(), Constants.REDBEAN_RATE, 2)) + "红豆/");

                        holder.rewardProjectMeidou.setVisibility(View.VISIBLE);
                        holder.rewardProjectItemMeidou.setVisibility(View.VISIBLE);
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                            holder.rewardProjectMeidou.setText(Html.fromHtml("<font color='#ff7f00'>" + context.getResources().getString(R.string.give_meidou) + data.getBackinnernum()
                                    + "美豆/</font><font color='#ff4c4c'>" +  CommonTool.getWhole(DataUtil.multiplys(data.getShouldprice(), Constants.REDBEAN_RATE, 2))  + "红豆</font>", Html.FROM_HTML_MODE_COMPACT));
                        } else {
                            holder.rewardProjectMeidou.setText(Html.fromHtml("<font color='#ff7f00'>" + context.getResources().getString(R.string.give_meidou) + data.getBackinnernum()
                                    + "美豆/</font><font color='#ff4c4c'>" +  CommonTool.getWhole(DataUtil.multiplys(data.getShouldprice(), Constants.REDBEAN_RATE, 2))  + "红豆</font>"));
                        }
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                            holder.rewardProjectItemMeidou.setText(Html.fromHtml("<font color='#ff7f00'>" + context.getResources().getString(R.string.give_meidou) + data.getBackinnernum()
                                    + "美豆/</font><font color='#ff4c4c'>" +  CommonTool.getWhole(DataUtil.multiplys(data.getShouldprice(), Constants.REDBEAN_RATE, 2))  + "红豆</font>", Html.FROM_HTML_MODE_COMPACT));
                        } else {
                            holder.rewardProjectItemMeidou.setText(Html.fromHtml("<font color='#ff7f00'>" + context.getResources().getString(R.string.give_meidou) + data.getBackinnernum()
                                    + "美豆/</font><font color='#ff4c4c'>" +  CommonTool.getWhole(DataUtil.multiplys(data.getShouldprice(), Constants.REDBEAN_RATE, 2))  + "红豆</font>"));
                        }
                    } else if (DataUtil.moreThanZero(data.getBackredbean()) && !DataUtil.moreThanZero(data.getBackinnernum())) {
                        holder.rewardProjectHongdou.setVisibility(View.VISIBLE);
                        holder.rewardProjectItemHongdou.setVisibility(View.VISIBLE);
                        holder.rewardProjectHongdou.setText(context.getResources().getString(R.string.award_hongdou) + data.getShouldprice() + "红豆");
                        holder.rewardProjectItemHongdou.setText(context.getResources().getString(R.string.award_hongdou) + data.getShouldprice() + "红豆");

                        holder.rewardProjectMeidou.setVisibility(View.GONE);
                        holder.rewardProjectItemMeidou.setVisibility(View.GONE);
                    } else if (!DataUtil.moreThanZero(data.getBackredbean()) && DataUtil.moreThanZero(data.getBackinnernum())) {
                        holder.rewardProjectHongdou.setVisibility(View.GONE);
                        holder.rewardProjectItemHongdou.setVisibility(View.GONE);

                        holder.rewardProjectMeidou.setVisibility(View.VISIBLE);
                        holder.rewardProjectItemMeidou.setVisibility(View.VISIBLE);
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                            holder.rewardProjectMeidou.setText(Html.fromHtml("<font color='#ff7f00'>" + context.getResources().getString(R.string.give_meidou) + data.getBackinnernum()
                                    + "美豆/</font><font color='#ff4c4c'>" +  CommonTool.getWhole(DataUtil.multiplys(data.getShouldprice(), Constants.REDBEAN_RATE, 2))  + "红豆</font>", Html.FROM_HTML_MODE_COMPACT));
                        } else {
                            holder.rewardProjectMeidou.setText(Html.fromHtml("<font color='#ff7f00'>" + context.getResources().getString(R.string.give_meidou) + data.getBackinnernum()
                                    + "美豆/</font><font color='#ff4c4c'>" +  CommonTool.getWhole(DataUtil.multiplys(data.getShouldprice(), Constants.REDBEAN_RATE, 2))  + "红豆</font>"));
                        }
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                            holder.rewardProjectItemMeidou.setText(Html.fromHtml("<font color='#ff7f00'>" + context.getResources().getString(R.string.give_meidou) + data.getBackinnernum()
                                    + "美豆/</font><font color='#ff4c4c'>" +  CommonTool.getWhole(DataUtil.multiplys(data.getShouldprice(), Constants.REDBEAN_RATE, 2))  + "红豆</font>", Html.FROM_HTML_MODE_COMPACT));
                        } else {
                            holder.rewardProjectItemMeidou.setText(Html.fromHtml("<font color='#ff7f00'>" + context.getResources().getString(R.string.give_meidou) + data.getBackinnernum()
                                    + "美豆/</font><font color='#ff4c4c'>" +  CommonTool.getWhole(DataUtil.multiplys(data.getShouldprice(), Constants.REDBEAN_RATE, 2))  + "红豆</font>"));
                        }
                    } else {
                        holder.rewardProjectHongdou.setVisibility(View.GONE);
                        holder.rewardProjectMeidou.setVisibility(View.GONE);
                        holder.rewardProjectItemHongdou.setVisibility(View.GONE);
                        holder.rewardProjectItemMeidou.setVisibility(View.GONE);
                    }
                } else {
                    holder.rewardProjectHongdou.setVisibility(View.GONE);
                    holder.rewardProjectMeidou.setVisibility(View.GONE);
                    holder.rewardProjectItemHongdou.setVisibility(View.GONE);
                    holder.rewardProjectItemMeidou.setVisibility(View.GONE);
                }

                if (null != data.getCtime() && !"".equals(data.getCtime())) {
                    holder.rewardProjectPaytime.setText("完成:" + data.getCtime());
                } else {
                    holder.rewardProjectPaytime.setText("");
                }
                if (null != data.getId() && !"".equals(data.getId())) {
                    holder.rewardProjectItemOrderNum.setText("订单编号:" + data.getId());
                } else {
                    holder.rewardProjectItemOrderNum.setText("");
                }


                if (null != data.getOrdertype() && !"".equals(data.getOrdertype())) {
                    if (data.getOrdertype().equals("1") || data.getOrdertype().equals("4")) { //邮寄  同城

                        holder.linearTop.setVisibility(View.GONE);
                        holder.linearTopStatus.setVisibility(View.VISIBLE);
                        holder.rewardProjectToView.setVisibility(View.VISIBLE);
                        holder.rewardProjectConfirm.setVisibility(View.GONE);

                        holder.linearCenter.setBackgroundColor(context.getResources().getColor(R.color.cart_background));
                        holder.linearBottom.setVisibility(View.VISIBLE);
                        holder.rewardProjectType.setTextColor(context.getResources().getColor(R.color.postCartItem));
                        if (data.getOrdertype().equals("1")) {
                            holder.rewardProjectItemTvSend.setVisibility(View.VISIBLE);
                            if (null != data.getGoodsnum() && !"".equals(data.getGoodsnum())) {
                                holder.rewardProjectType.setText("邮寄:" + data.getGoodsnum() + "件(已收货)");
                            } else {
                                holder.rewardProjectType.setText("");
                            }
                            if (null != data.getPostage() && null != data.getShouldprice()) {
                                String add = DataUtil.add(data.getShouldprice(), data.getPostage());
                                holder.rewardProjectMoney.setText(add + "元");

                                holder.rewardProjectItemAllCash.setText(data.getShouldprice() + "元");
                                holder.rewardProjectItemTvSend.setText("快递:" + data.getPostage() + "元");
                            } else {
                                holder.rewardProjectItemTvSend.setText("快递:0元");
                            }
                        } else {
                            holder.rewardProjectItemTvSend.setVisibility(View.GONE);
                            if (null != data.getGoodsnum() && !"".equals(data.getGoodsnum())) {
                                holder.rewardProjectType.setText("同城配送:" + data.getGoodsnum() + "件(已收货)");
                            } else {
                                holder.rewardProjectType.setText("");
                            }
                            if (!TextUtils.isEmpty(data.getShouldprice())) {
                                holder.rewardProjectMoney.setText(data.getShouldprice() + "元");
                                holder.rewardProjectItemAllCash.setText(data.getShouldprice() + "元");
                            } else {
                                holder.rewardProjectMoney.setText("");
                                holder.rewardProjectItemAllCash.setText("");
                            }
                        }
                        //查看物流信息
                        holder.rewardProjectToView.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                Message msg = Message.obtain();
                                msg.obj = position;
                                msg.what = 1;
                                handler.sendMessage(msg);
                            }
                        });

                        if (null != jsonObject && !"".equals(jsonObject)) {
                            String shopname = jsonObject.optString("name");
                            if (null != shopname && !"".equals(shopname)) {
                                holder.rewardPostShopName.setText(shopname);
                            } else {
                                holder.rewardPostShopName.setText("");
                            }
                            final String phone = jsonObject.optString("phone");
                            if (null != phone && !"".equals(phone)) {
                                holder.rewardPostShopPhone.setText(phone);
                            } else {
                                holder.rewardPostShopPhone.setText("");
                            }
                            holder.rewardPostShopCall.setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View view) {
                                    if (null != phone && !"".equals(phone)) {
                                        Intent intent = new Intent(Intent.ACTION_DIAL);
                                        Uri data = Uri.parse("tel:" + phone);
                                        intent.setData(data);
                                        context.startActivity(intent);
                                    } else {
                                        Toast.makeText(context, "联系方式不可用", Toast.LENGTH_SHORT).show();
                                    }
                                }
                            });
                        } else {
                            holder.rewardPostShopName.setText("");
                            holder.rewardPostShopPhone.setText("");
                        }
                        holder.rewardSendCash.setText(context.getResources().getString(R.string.goldenDesc)+ data.getShouldprice()+"元消费红包");
                        holder.rewardProjectItemSend.setText(context.getResources().getString(R.string.goldenDesc)+ data.getShouldprice()+"元消费红包");
                        JSONObject jsonCus = orderCus.optJSONObject(data.getId());
                        if (null != jsonCus && !"".equals(jsonCus)) {
                            String consignee = jsonCus.optString("consignee");
                            if (null != consignee && !"".equals(consignee)) {
                                holder.rewardGetName.setText(consignee);
                            } else {
                                holder.rewardGetName.setText("");
                            }
                            final String consigneemphone = jsonCus.optString("consigneemphone");
                            if (null != consigneemphone && !"".equals(consigneemphone)) {
                                holder.rewardGetPhone.setText(consigneemphone);
                            } else {
                                holder.rewardGetPhone.setText("");
                            }
                            String shippercode = jsonCus.optString("shippercode");
                            String logisticscode = jsonCus.optString("logisticscode");
                            JSONObject jsonLogis = new JSONObject(MyApplication.getInstance().getLogistics());
                            if (null != shippercode && !"".equals(shippercode) && null != logisticscode) {
                                holder.rewardProjectStatus.setText(jsonLogis.optString(shippercode) + ":" + logisticscode);
                            } else {
                                holder.rewardProjectStatus.setText("暂无物流信息");
                            }

                            String shippingaddress = jsonCus.optString("shippingaddress");
                            if (null != shippingaddress && !"".equals(shippingaddress)) {
                                holder.rewardGetAddress.setText(shippingaddress);
                            } else {
                                holder.rewardGetAddress.setText("");
                            }

                        } else {
                            holder.rewardGetName.setText("");
                            holder.rewardGetPhone.setText("");
                            holder.rewardGetAddress.setText("");
                        }

                    } else {//自提
                        holder.linearTop.setVisibility(View.VISIBLE);
                        holder.linearCenter.setBackgroundColor(context.getResources().getColor(R.color.bg_time));
                        holder.linearBottom.setVisibility(View.GONE);
                        holder.rewardProjectType.setTextColor(context.getResources().getColor(R.color.title_blue));
                        holder.linearShopPhone1.setVisibility(View.GONE);
                        holder.linearShopPhone2.setVisibility(View.VISIBLE);
                        holder.rewardZiTiCall.setVisibility(View.VISIBLE);
                        holder.rewardZiTiNavigate.setVisibility(View.VISIBLE);
                        holder.linearTopStatus.setVisibility(View.GONE);
                        holder.rewardProjectItemTvSend.setVisibility(View.GONE);


                        if (null != data.getGoodsnum() && !"".equals(data.getGoodsnum())) {
                            holder.rewardProjectType.setText("上门自提/消费:" + data.getGoodsnum() + "件");
                        } else {
                            holder.rewardProjectType.setText("");
                        }

                        if (null != data.getShouldprice() && !"".equals(data.getShouldprice())) {
                            holder.rewardProjectItemAllCash.setText(data.getShouldprice() + "元");

                        } else {
                            holder.rewardProjectItemAllCash.setText("");
                        }

                        if (null != data.getShouldprice() && !"".equals(data.getShouldprice())) {
                            holder.rewardProjectMoney.setText(data.getShouldprice() + "元");
                        } else {
                            holder.rewardProjectMoney.setText("");
                        }
                        holder.rewardSendCash.setText(context.getResources().getString(R.string.goldenDesc)+ data.getShouldprice()+"元消费红包");
                        holder.rewardProjectItemSend.setText(context.getResources().getString(R.string.goldenDesc)+ data.getShouldprice()+"元消费红包");

                        //自提商家信息
                        if (null != jsonObject && !"".equals(jsonObject)) {
                            String shopname = jsonObject.optString("name");
                            if (null != shopname && !"".equals(shopname)) {
                                holder.rewardShopName.setText(shopname);
                            } else {
                                holder.rewardShopName.setText("");
                            }
                            final String phone = jsonObject.optString("phone");
                            if (null != phone && !"".equals(phone)) {
                                holder.rewardShopPhone2.setText(phone);
                            } else {
                                holder.rewardShopPhone2.setText("");
                            }
                            holder.rewardZiTiCall.setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View view) {
                                    if (null != phone && !"".equals(phone)) {
                                        Intent intent = new Intent(Intent.ACTION_DIAL);
                                        Uri data = Uri.parse("tel:" + phone);
                                        intent.setData(data);
                                        context.startActivity(intent);
                                    } else {
                                        Toast.makeText(context, "联系方式不可用", Toast.LENGTH_SHORT).show();
                                    }
                                }
                            });
                            String address = jsonObject.optString("address");
                            if (null != address && !"".equals(address)) {
                                holder.rewardShopAddress.setText(address);
                                holder.rewardZiTiNavigate.setOnClickListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View view) {
                                        dimensions = jsonObject.optString("dimensions");
                                        longitude = jsonObject.optString("longitude");
                                        if (dimensions != null && longitude != null) {
                                            if (dialog == null) {
                                                dialog = new ProgressDialog(context);
                                            }
                                            dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);  //样式为圆形
                                            dialog.setCancelable(false);
                                            dialog.setOnKeyListener(keyListener);
                                            dialog.setMessage("正在获取数据,请稍后...");
                                            dialog.show();
                                            if (dimensions != null && longitude != null) {
                                                if (BaiduNaviManager.isNaviInited()) {
                                                    routeplanToNavi(BNRoutePlanNode.CoordinateType.BD09LL);
                                                }
                                            } else {
                                                if (dialog != null && dialog.isShowing()) {
                                                    dialog.dismiss();
                                                }
                                                Toast.makeText(context, "位置信息不完整，无法计算路线", Toast.LENGTH_SHORT).show();
                                            }
                                        } else {
                                            Toast.makeText(context, "位置信息不完整，无法计算路线", Toast.LENGTH_SHORT).show();
                                        }
                                    }
                                });
                            } else {
                                holder.rewardShopAddress.setText("");
                            }
                        } else {
                            holder.rewardShopName.setText("");
                            holder.rewardShopPhone.setText("");
                            holder.rewardShopAddress.setText("");
                        }
                    }
                }
                final List<MirrorInfo> mirrorInfoList = new ArrayList<>();
                List<String> imageList = new ArrayList<>();
                JSONArray jsonArray = info.optJSONArray(data.getId());
                for (int i = 0; i < jsonArray.length(); i++) {
                    JSONObject jsonObject1 = (JSONObject) jsonArray.get(i);
                    MirrorInfo mirrorInfo = MirrorInfo.parseMatch(jsonObject1);
                    mirrorInfoList.add(mirrorInfo);
                    imageList.add(mirrorInfo.getThumbnail());
                }
                if (imageList.size() == 1) {
                    holder.ivSingleImg.setVisibility(View.VISIBLE);
                    holder.gvImg.setVisibility(View.GONE);
                    Glide.with(context).load(Url.IMG_URL + imageList.get(0)).placeholder(R.mipmap.iv_eg).fitCenter().into(holder.ivImg);
                } else {
                    holder.ivSingleImg.setVisibility(View.GONE);
                    holder.gvImg.setVisibility(View.VISIBLE);
                    holder.gvList.setAdapter(new GridOrderAdapter(context, imageList));
                }
                holder.lvList.setAdapter(new RewardOrderAdapter(context, mirrorInfoList));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return convertView;
    }

    public void setInfo(JSONObject info) {
        this.info = info;
    }

    public void setShopInfo(JSONObject shopInfo) {
        this.shopInfo = shopInfo;
    }

    public void setOrderCus(JSONObject orderCus) {
        this.orderCus = orderCus;
    }

    private boolean hasCompletePhoneAuth() {
        PackageManager pm = context.getPackageManager();
        for (String auth : authComArr) {
            if (pm.checkPermission(auth, context.getPackageName()) != PackageManager.PERMISSION_GRANTED) {
                return false;
            }
        }
        return true;
    }

    private void routeplanToNavi(BNRoutePlanNode.CoordinateType coType) {
        // 权限申请
        if (android.os.Build.VERSION.SDK_INT >= 23) {
            // 保证导航功能完备
            if (!hasCompletePhoneAuth()) {
                if (!hasRequestComAuth) {
                    hasRequestComAuth = true;
                    fragment.requestPermissions(authComArr, authComRequestCode);
                    return;
                }
            }

        }
        BNRoutePlanNode sNode = null;
        BNRoutePlanNode eNode = null;
        switch (coType) {
            case BD09LL: {
                sNode = new BNRoutePlanNode(Double.parseDouble(MyApplication.getInstance().getLongitude()), Double.parseDouble(MyApplication.getInstance().getLatitude()), "出发地", null, coType);
                eNode = new BNRoutePlanNode(Double.parseDouble(longitude), Double.parseDouble(dimensions), "超市", null, coType);
                break;
            }
            default:
        }
        if (sNode != null && eNode != null) {
            List<BNRoutePlanNode> list = new ArrayList<BNRoutePlanNode>();
            list.add(sNode);
            list.add(eNode);
            BaiduNaviManager.getInstance().launchNavigator((Activity) context, list, 1, true, new DemoRoutePlanListener(sNode));
        }
    }

    public class DemoRoutePlanListener implements BaiduNaviManager.RoutePlanListener {

        private BNRoutePlanNode mBNRoutePlanNode = null;

        public DemoRoutePlanListener(BNRoutePlanNode node) {
            mBNRoutePlanNode = node;
        }

        @Override
        public void onJumpToNavigator() {
            if (dialog != null && dialog.isShowing()) {
                dialog.dismiss();
            }

//             * 设置途径点以及resetEndNode会回调该接口


            for (Activity ac : RewardCoinOrderActivity.activityList) {

                if (ac.getClass().getName().endsWith("MapNaviActivity")) {

                    return;
                }
            }
            Intent intent = new Intent(context, MapNaviActivity.class);
            Bundle bundle = new Bundle();
            bundle.putSerializable(RewardCoinOrderActivity.ROUTE_PLAN_NODE, (BNRoutePlanNode) mBNRoutePlanNode);
            intent.putExtras(bundle);
            intent.putExtra("type", "2");
            context.startActivity(intent);

        }

        @Override
        public void onRoutePlanFailed() {
            if (dialog != null && dialog.isShowing()) {
                dialog.dismiss();
            }
            Toast.makeText(context, "导航失败", Toast.LENGTH_SHORT).show();
        }
    }

    class ViewHolder {
        private ImageView ivImg;
        private View ivSingleImg;
        private View gvImg;
        private View listMenu;

        private NoScrollGridView gvList;
        private TextView rewardProjectType, rewardProjectMoney, rewardProjectHongdou, rewardProjectMeidou, rewardProjectPaytime, rewardProjectToPay, rewardProjectDelete;

        private TextView rewardProjectStatus, rewardProjectConfirm, rewardProjectToView;
        private TextView rewardShopName, rewardZiTiCall, rewardZiTiNavigate, rewardShopPhone, rewardShopPhone2, rewardShopAddress;

        private TextView rewardProjectItemOrderNum;
        private LinearLayout linearTop;
        private NoScrollListView lvList;
        private TextView rewardProjectItemAllCash, rewardProjectItemHongdou, rewardProjectItemMeidou, rewardProjectItemTvSend, rewardGetName, rewardGetPhone, rewardGetAddress;
        private TextView rewardPostShopCall, rewardPostShopName, rewardPostShopPhone;
        private RelativeLayout linearTopStatus;
        private LinearLayout linearBottom, linearShopPhone1, linearShopPhone2;
        private LinearLayout linearCenter;
        private TextView rewardSendCash;
        private TextView rewardProjectItemSend;
    }
}
